package test.threads.queue.unstressed.impl;

import test.threads.queue.stressed.cpu.LongValueMessage;
import test.threads.queue.unstressed.IBoundedQueueFactory;
import test.threads.queue.unstressed.IQueue;

/**
 * Фальшивая реализация -- для измерения погрешностей, вносимых в измерения
 * нашей инфраструктурой
 *
 * @author cheremin
 * @since 22.09.11,  13:09
 */
public class FakeQueue<T> implements IQueue<T> {

    private final LongValueMessage message = new LongValueMessage( 42 );

    public FakeQueue( final int size ) {
    }

    @Override
    public void enqueue( final T item ) throws InterruptedException {
    }

    @Override
    public T dequeue() throws InterruptedException {
        return ( T ) message;
    }

    @Override
    public int size() {
        return 0;
    }

    @SuppressWarnings( "unchecked" )
    public static <T> IBoundedQueueFactory<T, FakeQueue<T>> factory() {
        return FACTORY;
    }

    public static final IBoundedQueueFactory FACTORY = new IBoundedQueueFactory<Object, FakeQueue<Object>>() {
        @Override
        public FakeQueue<Object> create( final int size ) {
            return new FakeQueue<Object>( size );
        }

        @Override
        public String toString() {
            return "DummyFactory";
        }
    };
}
